package com.novel.controller;

import com.github.pagehelper.PageInfo;
import com.novel.service.ScoreService;
import com.reading.pojo.NovelScore;
import com.reading.pojo.Score;
import com.reading.vo.Rmed;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("score")
public class ScoreController {
    @Resource
    private ScoreService scoreService;

    @RequestMapping("list")
    public Rmed list(Integer pid) {
        return Rmed.suceessData(scoreService.list(pid));
    }

    @RequestMapping("findbyid")
    public Rmed findbyid(Integer pid) {
        return Rmed.suceessData(scoreService.findbyid(pid));
    }

    @RequestMapping("findall")
    public Rmed findall(Integer pid) {
        return Rmed.suceessData(scoreService.findall(pid));
    }

    @RequestMapping("/findAllScore")
    public List<Score> findAllScore(){
        return scoreService.findAllScore();
    }

    @RequestMapping("/findcomment")
    public Rmed findcomment(@RequestBody NovelScore novelScore, Integer pageNo, Integer pageSize){
        PageInfo pageInfo = scoreService.findcomment(novelScore,pageNo,pageSize);
        return Rmed.suceessData(pageInfo);
    }

    @RequestMapping("add")
    public Rmed add(@RequestBody NovelScore novelScore) {
        return Rmed.suceessData(scoreService.add(novelScore));
    }

    @RequestMapping("findid")
    public Rmed findid(Integer id){
        return Rmed.suceessData(scoreService.findid(id));
    }

    @RequestMapping("findalluser")
    public Rmed findalluser(Integer uid){
        return Rmed.suceessData(scoreService.findalluser(uid));
    }

    @RequestMapping("delete")
    public Rmed delete(Integer id){
        try {
            scoreService.delete(id);
            return Rmed.suceessData("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("删除失败");
    }
}
